package com.dk.controller;

import com.dk.pojo.MdVendor;
import com.dk.result.PageResult;
import com.dk.result.Result;
import com.dk.result.ResultConstant;
import com.dk.service.VendorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LTZ
 * @create 2023/5/11
 */
@RestController
@RequestMapping("vendor")
@Api(tags = "供应商文档接口")
public class VendorController {

    @Autowired
    private VendorService vendorService;

    @GetMapping("getVendorInfo")
    @ApiOperation("供应商模糊查询和分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数"),
            @ApiImplicitParam(name = "vendorCode", value = "供应商编码"),
            @ApiImplicitParam(name = "vendorName", value = "供应商名称"),
            @ApiImplicitParam(name = "enableFlag", value = "是否启用")
    })
    public Result getVendorInfo(@RequestParam(defaultValue = "1")Integer pageNum,
                                @RequestParam(defaultValue = "5") Integer pageSize,
                                String vendorCode, String vendorName,String enableFlag){
        PageResult<MdVendor> result = vendorService.getVendorInfo(pageNum,pageSize,vendorCode,vendorName,enableFlag);
        return new Result(ResultConstant.CODE,ResultConstant.MESSAGE,result);
    }

    @PostMapping("addVendor")
    @ApiOperation("供应商增加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vendorCode",value = "供应商编码",required = true),
            @ApiImplicitParam(name = "vendorName",value = "供应商名称",required = true),
            @ApiImplicitParam(name = "vendorNick",value = "供应商简称",required = true),
            @ApiImplicitParam(name = "vendorEn",value = "供应商英文名",required = true),
            @ApiImplicitParam(name = "vendorDes",value = "供应商简介",required = false),
            @ApiImplicitParam(name = "vendorLogo",value = "供应商LOGO地址",required = true),
            @ApiImplicitParam(name = "vendorLevel",value = "供应商等级",required = true),
            @ApiImplicitParam(name = "vendorScore",value = "供应商评分",required = true),
            @ApiImplicitParam(name = "address",value = "供应商地址",required = true),
            @ApiImplicitParam(name = "website",value = "供应商官网地址",required = true),
            @ApiImplicitParam(name = "email",value = "供应商邮箱地址",required = false),
            @ApiImplicitParam(name = "tel",value = "供应商电话",required = false),
            @ApiImplicitParam(name = "contact1",value = "联系人1",required = false),
            @ApiImplicitParam(name = "contact1Tel",value = "联系人1-电话",required = false),
            @ApiImplicitParam(name = "contact1Email",value = "联系人1-邮箱",required = false),
            @ApiImplicitParam(name = "contact2",value = "联系人2",required = false),
            @ApiImplicitParam(name = "contact2Tel",value = "联系人2-电话",required = false),
            @ApiImplicitParam(name = "contact2Email",value = "联系人2-邮箱",required = false),
            @ApiImplicitParam(name = "creditCode",value = "统一社会信用代码",required = false),
            @ApiImplicitParam(name = "enableFlag",value = "是否启用",required = true),
            @ApiImplicitParam(name = "remark",value = "备注",required = false),
            @ApiImplicitParam(name = "token", value = "登录后返回的token串",required = true)
    })
    public Result addVendor(MdVendor vendor, @RequestHeader String token){
        if(token == null || "".equals(token)){
            return new Result(ResultConstant.TOKEN_CODE, ResultConstant.TOKEN_MESSAGE);
        }
        return vendorService.addVendor(vendor,token);
    }

    @PutMapping("updateVendor")
    @ApiOperation("供应商修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vendorId",value = "供应商id",required = true),
            @ApiImplicitParam(name = "vendorCode",value = "供应商编码"),
            @ApiImplicitParam(name = "vendorName",value = "供应商名称"),
            @ApiImplicitParam(name = "vendorNick",value = "供应商简称"),
            @ApiImplicitParam(name = "vendorEn",value = "供应商英文名"),
            @ApiImplicitParam(name = "vendorDes",value = "供应商简介"),
            @ApiImplicitParam(name = "vendorLogo",value = "供应商LOGO地址"),
            @ApiImplicitParam(name = "vendorLevel",value = "供应商等级"),
            @ApiImplicitParam(name = "vendorScore",value = "供应商评分"),
            @ApiImplicitParam(name = "address",value = "供应商地址"),
            @ApiImplicitParam(name = "website",value = "供应商官网地址"),
            @ApiImplicitParam(name = "email",value = "供应商邮箱地址"),
            @ApiImplicitParam(name = "tel",value = "供应商电话"),
            @ApiImplicitParam(name = "contact1",value = "联系人1"),
            @ApiImplicitParam(name = "contact1Tel",value = "联系人1-电话"),
            @ApiImplicitParam(name = "contact1Email",value = "联系人1-邮箱"),
            @ApiImplicitParam(name = "contact2",value = "联系人2"),
            @ApiImplicitParam(name = "contact2Tel",value = "联系人2-电话"),
            @ApiImplicitParam(name = "contact2Email",value = "联系人2-邮箱"),
            @ApiImplicitParam(name = "creditCode",value = "统一社会信用代码"),
            @ApiImplicitParam(name = "enableFlag",value = "是否启用"),
            @ApiImplicitParam(name = "remark",value = "备注"),
            @ApiImplicitParam(name = "token", value = "登录后返回的token串",required = true)
    })
    public Result updateVendor(MdVendor vendor, @RequestHeader String token){
        if(token == null || "".equals(token)){
            return new Result(ResultConstant.TOKEN_CODE, ResultConstant.TOKEN_MESSAGE);
        }
        return vendorService.updateVendor(vendor,token);
    }

    @DeleteMapping("deleteVendor")
    @ApiOperation("供应商删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vendorId", value = "供应商id",required = true)
    })
    public Result deleteVendor(Long vendorId){
        vendorService.deleteVendor(vendorId);
        return new Result(ResultConstant.CODE,ResultConstant.MESSAGE);
    }

    @GetMapping("selectByVendorCode")
    public MdVendor selectByVendorCode(@RequestParam String vendorCode){
        return vendorService.selectByVendorCode(vendorCode);
    }
}